import { defineConfig, loadEnv } from "vite";
import vue from "@vitejs/plugin-vue";
import Components from "unplugin-vue-components/vite";
import { AntDesignVueResolver } from "unplugin-vue-components/resolvers";
import { AntDesignXVueResolver } from "ant-design-x-vue/resolver";
import path from "path";

// https://vite.dev/config/
export default defineConfig(({ mode }) => {
  const env = loadEnv(mode, process.cwd());
  return {
    plugins: [
      vue(),
      Components({
        resolvers: [
          AntDesignXVueResolver(),
          AntDesignVueResolver({
            importStyle: "css-in-js",
          }),
        ],
        dts: true,
      }),
    ],
    resolve: {
      alias: {
        "@": path.resolve(__dirname, "./src"),
      },
    },
    server: {
      port: 3000, // 首选端口
      strictPort: false, // 设为 false 允许自动切换到下一个可用端口
    },
    css: {
      preprocessorOptions: {
        less: {
          modifyVars: {
            "primary-color": "#1890ff",
          },
          javascriptEnabled: true,
        },
      },
    },
  };
});
